#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=210;
int n,a[MAXN],b[MAXN],c[MAXN],head[MAXN],cnt,ans;
bool belog[MAXN];
struct edge
{
	int v,next,flow;
	LL cost;
}e[MAXN*MAXN*2];
void addedge(int x,int y,int f,LL c)
{
	e[cnt]=(edge){y,head[x],f,c};
	head[x]=cnt++;
	swap(x,y);
	e[cnt]=(edge){y,head[x],0,-c};
	head[x]=cnt++;
	return;
}
struct MCMF
{
	int lst[MAXN],S,T,flow;
	LL dis[MAXN],cost;
	bool vis[MAXN];
	bool SPFA()
	{
		for(int i=S;i<=T;++i)dis[i]=-100000000000;
		queue<int>q;
		q.push(S);
		vis[S]=true;
		dis[S]=0;
		while(!q.empty())
		{
			int u=q.front();q.pop();vis[u]=false;
			for(int i=head[u];~i;i=e[i].next)
			{
				int v=e[i].v;
				if(e[i].flow&&dis[v]<dis[u]+e[i].cost)
				{
					dis[v]=dis[u]+e[i].cost;
					lst[v]=i;
					if(!vis[v])
					{
						vis[v]=true;
						q.push(v);
					}
				}
			}
		}
		return dis[T]!=-100000000000;
	}
	void EK()
	{
		memset(lst,-1,sizeof(lst));
		while(SPFA())
		{
			int _min=INF;
			for(int i=lst[T];~i;i=lst[e[i^1].v])
				_min=min(_min,e[i].flow);
			if(cost+(LL)_min*dis[T]<0)
				return (void)(flow+=cost/-dis[T]);
			flow+=_min;
			cost+=(LL)_min*dis[T];
			for(int i=lst[T];~i;i=lst[e[i^1].v])
				e[i].flow-=_min,e[i^1].flow+=_min;
		}
		return;
	}
}T1;
struct MRPR
{
	int ans;
	int qpow(int a,int b,int mod)
	{
		int ret=1;
		for(;b;b>>=1,a=(LL)a*a%mod)
			if(b&1)ret=(LL)ret*a%mod;
		return ret;
	}
	bool MR(int x)
	{
		if(x==2||x==3)return true;
		if(x==1||!(x&1))return false;
		for(int i=1;i<=20;++i)
		{
			int a=rand()%(x-2)+2,k=x-1,r=0;
			while(!(k&1))++r,k>>=1;
			a=qpow(a,k,x);
			int t=a;
			while(r--)
			{
				a=(LL)a*a%x;
				if(a==1&&t!=1&&t!=x-1)return false;
				t=a;
			}
			if(a!=1)return false;
		}
		return true;
	}
	inline int f(int x,int c,int n)
	{
		return (x*x%n+c)%n;
	}
	int PR(int n,int c)
	{
		int x=rand()%n,y=f(x,c,n),p;
		for(;;)
		{
			p=__gcd(abs(x-y),n);
			if(p>1&&p<n)return p;
			x=f(x,c,n);y=f(f(y,c,n),c,n);
			if(x==y)return n;
		}
	}
	void find(int x)
	{
		if(x==1)return;
		if(MR(x))return (void)(++ans);
		int t=x;
		while(t==x)t=PR(t,rand()%(x-1)+1);
		find(x/t);
		find(t);
		return;
	}
}T2;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();
	memset(head,-1,sizeof(head));
	int S=0,T=n+1;
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=1;i<=n;++i)b[i]=read();
	for(int i=1;i<=n;++i)c[i]=read();
	for(int i=1;i<=n;++i)
	{
		T2.ans=0;
		T2.find(a[i]);
		if(T2.ans&1)addedge(S,i,b[i],0),belog[i]=true;
		else addedge(i,T,b[i],0);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(belog[i]^belog[j]&&a[i]%a[j]==0&&T2.MR(a[i]/a[j]))
			{
				if(belog[i])addedge(i,j,INF,(LL)c[i]*c[j]);
				else addedge(j,i,INF,(LL)c[i]*c[j]);
			}
	T1.S=S;T1.T=T;
	T1.EK();
	printf("%d\n",T1.flow);
	return 0;
}
